import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# 启动Edge浏览器
driver = webdriver.Chrome()

# 打开页面
driver.get("file:///F:/TestProject/register.html")

# 等待元素可见并点击按钮触发弹出框
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.ID, "alerta")))
driver.find_element(By.ID, "alerta").click()
alert_text = driver.switch_to.alert.text
print("提示框文本：", alert_text)
driver.switch_to.alert.accept()  # 点击确定
time.sleep(5)

# 等待元素可见并点击按钮触发确认框
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.ID, "confirma")))
driver.find_element(By.ID, "confirma").click()
confirm_text = driver.switch_to.alert.text
print("确认框文本：", confirm_text)
driver.switch_to.alert.dismiss()  # 点击取消
time.sleep(5)

# 等待元素可见并点击按钮触发输入框
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.ID, "prompta")))
driver.find_element(By.ID, "prompta").click()
prompt_text = driver.switch_to.alert.text
print("输入框文本：", prompt_text)
driver.switch_to.alert.send_keys("Kimi")  # 输入内容
driver.switch_to.alert.accept()  # 点击确定
time.sleep(5)

# 关闭浏览器
driver.quit()